package com.aratek.salary.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

/**
 * RunConfig
 *
 * @author yvan
 * @version 2024/10/30 10:16
 **/
@Configuration
public class RunConfig implements CommandLineRunner {

    private static final Logger log = LoggerFactory.getLogger(RunConfig.class);
    @Value("${open-project.is-open}")
    private boolean isOpen;

    @Value("${open-project.web.open-url}")
    private String openUrl;

    @Value("${open-project.cmd}")
    private String cmd;

    @Override
    public void run(String... args){
        if(isOpen){
            String runCmd = cmd + " " + openUrl ;
            log.info("运行的命令: {}", runCmd);
            Runtime run = Runtime.getRuntime();
            try {
                run.exec(runCmd);
                log.info("启动浏览器打开项目成功");
            } catch (Exception e) {
                log.info("启动项目自动打开浏览器失败");
            }
        }
    }
}

